<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // alert("Hello JavaScript!")

        // 变量要写在script里面,搭配控制台学习
        //script 是弱类型的,变量的类型可能会发生改变

        //定义变量用var或let都行,定义常量用const
        let name = "zhangsan";
        console.log(name);
        console.log(typeof name)

        name = 10;
        //类型 number string Boolean undefined
        console.log(name)
        console.log(typeof name)

        //==值比较
        //===值和类型比较

        //离谱的语言,包容度很大
        let array = ["aa", 10];
        console.log(array[6]);
        //增加(不正经)
        array[-1] = "dd";
        array[hello] = "ee";
        //改
        array[0] = "aao"
        //删
        array.splice(1, 1)//从下标1开始,删除1个元素

        //函数
        function add(x, y) {
            return x + y;
        }
        //函数调用
        let num = add(19, 19);//需要返回结果就接收
        console.log(num);
        add(12, 23, 34);//参数多了,多余的舍弃
        add(33)//参数少了,输出NaN,Not a number
        add("10")//输出10undefined
        function hello(s) {
            alert(s);
        }
        //匿名函数
        var add = function () {
            var sum = 0;
            for (var i = 0; i < arguments.length; i++) {
                sum += arguments[i];
            }
            return sum;
        }
        console.log(add(10, 20)); // 30
        console.log(add(1, 2, 3, 4)); // 10
        console.log(typeof add);

    </script>
    <!--  -->

</body>

</html>